package com.lyz.myself.service.ServiceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lyz.myself.config.utils.util.DateUtil;
import com.lyz.myself.controller.BaseController;
import com.lyz.myself.mapper.LeadsDataMapper;
import com.lyz.myself.mapper.LeadsMapper;
import com.lyz.myself.mapper.RFileLeadsMapper;
import com.lyz.myself.pojo.AssistPo.AssistLeads;
import com.lyz.myself.pojo.Po.Leads;
import com.lyz.myself.pojo.Po.LeadsData;
import com.lyz.myself.pojo.Po.RFileLeads;
import com.lyz.myself.service.LeadsService;
import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @program: myself
 * @Date: 2019/2/14 15:59
 * @Author: Mr.Deng
 * @Description:
 */
@Service
public class LeadsServiceImpl implements LeadsService {

    @Autowired
    LeadsMapper leadsMapper;

    @Autowired
    LeadsDataMapper leadsDataMapper;

    @Autowired
    RFileLeadsMapper rFileLeadsMapper;

    /**
     * 添加线索
     *
     * @param record
     * @return
     */
    @Override
    public int insertSelective(Leads record){
        return leadsMapper.insertSelective(record);
    }

    /**
     * 修改线索
     *
     * @param record
     * @return
     */
    @Override
    public int updateByPrimaryKeySelective(Leads record) {
        return leadsMapper.updateByPrimaryKeySelective(record);
    }

    /**
     * 根据id查看线索信息
     *
     * @param leads_id
     * @param company_id
     *
     *
     * @return
     */
    @Override
    public List<Map<String, String>> selectByPrimaryKey(Integer leads_id, Integer company_id) {
        return leadsMapper.selectByPrimaryKey(leads_id, company_id);
    }

    /**
     * 根据id 删除线索(可批量删除）
     *
     * @param delete_role_id
     * @param company_id
     * @param delete_time
     * @param list
     * @return
     */
    @Override
    public int deleteLeads(Integer delete_role_id, Integer company_id, Integer delete_time, List<Integer> list) {
        int deleteCustomer = leadsMapper.deleteLeads(delete_role_id, company_id, delete_time, list);
        return deleteCustomer;
    }

    /**
     * 我的线索
     */
    @Override
    public PageInfo<Map<String, Object>> selectAllLeads(Map<String, Object> map) {
        PageHelper.startPage((Integer) map.get("pageNum"), (Integer) map.get("pageSize"));
        List<Map<String, Object>> userList = leadsMapper.selectAllLeads(map);
        PageInfo<Map<String, Object>> page = new PageInfo<>(userList);
        return page;
    }

    /**
     * 线索池（可查看本公司下所有的线索）
     *
     * @param
     * @param map
     * @return
     */
    @Override
    public PageInfo<Map<String, Object>> selectAllPool(Map<String, Object> map) {
        PageHelper.startPage((Integer) map.get("pageNum"), (Integer) map.get("pageSize"));
        List<Map<String, Object>> userList = leadsMapper.selectAllPool(map);
        PageInfo<Map<String, Object>> page = new PageInfo<>(userList);
        return page;
    }

    /**
     * 领取线索
     *
     * @param list
     * @param have_time
     * @return
     */
    public int getToReceive(List<Integer> list, Integer have_time, Integer owner_role_id) {
        return leadsMapper.getToReceive(list, have_time, owner_role_id);
    }

    /**
     * 放入线索池
     *
     * @param list
     * @return
     */
    public int putCuePool(@Param("list") List<Integer> list) {
        return leadsMapper.putCuePool(list);
    }

}